package com.pipe.servicepipe.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @ClassName OpenURLConfig
 * @Author HETAO
 * @Date 2020/7/4 17:57
 */
@Component
public class OpenURLRunner implements CommandLineRunner {
    @Value("${url.open}")
    private boolean urlOpen;
    @Value("http://127.0.0.1:${server.port}")
    private String url;
    @Override
    public void run(String... args) throws Exception {
        Runtime exe = Runtime.getRuntime();
        StringBuilder sb = new StringBuilder();
        if (urlOpen) {
            String system = System.getProperty("os.name");
            if (system.startsWith("MAC ")) {
               sb.append("open "+url);
            }else if (system.startsWith("Windows ")) {
                sb.append("explorer "+ url);
            }
            exe.exec(sb.toString());
        }
    }
}
